//委托单位联系人管理 显示表格及js实体

Ext.define('AgentLinkman', {
    extend: 'Ext.data.Model',
    fields: [
        "Id"
		, "AgentId"   //委托单位Id
		, "AgentName"   //委托单位名称
		, "LinkmanName"   //联系人姓名
		, "Department"   //所在部门
		, "Position"   //职务
		, "Email"   //联系邮箱
		, "OfficialTel"   //办公电话
		, "OfficialMobile"   //办公移动电话
		, "Remark"   //备注
	],
    idProperty: "Id"
});

Ext.define('SHApp.CompanyManage.AgentLinkman.Grid', {
    extend: 'BLBTSystem.grid',
    alias: 'shapp.companymanage.grid',
    requires: ['SHApp.CompanyManage.AgentLinkman.Form'],
    txtAgentNameID: 'txtAgentName',
    txtLinkmanNameID: 'txtLinkmanName',
    dataModel: "AgentLinkman",
    dataUrl: "api/agentlinkman?format=json",
    initComponent: function () {
        var me = this;
        Ext.apply(this);
        me.btnAddID += me.id;
        me.btnEditID += me.id;
        me.btnDeleteID += me.id;
        me.txtAgentNameID += me.id;
        me.txtLinkmanNameID += me.id;
        this.creatTbar();
        this.creatColumns();
        this.callParent(arguments);
        this.checkBtnPermission(me.pvalue);
    },
    creatColumns: function () {
        var me = this;
        me.columns = [{
            text: "Id",
            flex: 1,
            dataIndex: 'Id',
            sortable: false,
            hidden: true
        }, {
            text: "委托单位Id",
            width: 100,
            dataIndex: 'AgentId',
            sortable: true,
            hidden: true
        }, {
            text: "委托单位名称",
            width: 150,
            dataIndex: 'AgentName',
            sortable: true
        }, {
            text: "联系人姓名",
            width: 100,
            dataIndex: 'LinkmanName',
            sortable: true
        }, {
            text: "所在部门",
            width: 100,
            dataIndex: 'Department',
            sortable: true
        }, {
            text: "职务",
            width: 100,
            dataIndex: 'Position',
            sortable: true
        }, {
            text: "联系邮箱",
            width: 120,
            dataIndex: 'Email',
            sortable: true
        }, {
            text: "办公电话",
            width: 120,
            dataIndex: 'OfficialTel',
            sortable: true
        }, {
            text: "办公移动电话",
            width: 120,
            dataIndex: 'OfficialMobile',
            sortable: true
        }, {
            text: "备注",
            width: 100,
            dataIndex: 'Remark',
            sortable: true
        }
		]
    },
    creatTbar: function () {
        var me = this;
        me.tbar = [{
            xtype: 'textfield',
            disabled: false,
            fieldLabel: '委托单位:',
            labelWidth: 60,
            name: 'AgentName',
            id: me.txtAgentNameID,
            width: 240
        }, {
            xtype: 'textfield',
            disabled: false,
            fieldLabel: '联系人姓名:',
            labelWidth: 70,
            name: 'LinkmanName',
            id: me.txtLinkmanNameID,
            width: 190
        }, ' ',{
            xtype: 'button',
            text: '查询',
            iconCls: 'icon-btn-search',
            handler: function () {
                me.clearFilters();
                var vAgentName = me.down("#" + me.txtAgentNameID).getValue();
                if (vAgentName && vAgentName.length > 0) {
                    me.addFilter("AgentName", vAgentName);
                }

                var vLinkmanName = me.down("#" + me.txtLinkmanNameID).getValue();
                if (vLinkmanName && vLinkmanName.length > 0) {
                    me.addFilter("LinkmanName", vLinkmanName);
                }

                me.loadByFilter();
            }
        }, '->', {
            xtype: 'button',
            text: '添加',
            id: me.btnAddID,
            iconCls: 'icon-btn-add',
            handler: function () {
                var win = me.getForm('SHApp.CompanyManage.AgentLinkman.Form');
                win.loadRecord(new AgentLinkman({ Id: null }));
                win.Show("添加");
            }
        }, ' ', {
            xtype: 'button',
            disabled: true,
            id: me.btnEditID,
            text: '修改',
            iconCls: 'icon-btn-edit',
            handler: function () {
                var rs = me.getSelectionModel().getSelection();
                if (rs) {
                    if (rs.length > 0) {
                        // rs[0].data.StartDate = formatDate(rs[0].data.StartDate);                           
                        me.EditData(me.getForm('SHApp.CompanyManage.AgentLinkman.Form'));
                    }
                }
            }
        }, ' ', {
            xtype: 'button',
            disabled: true,
            id: me.btnDeleteID,
            text: '删除',
            iconCls: 'icon-btn-delete',
            handler: function () {
                me.DeleteData();
            }
        }
        ]
    }
})

